#!/bin/sh
#
#   http://code.google.com/media-translate/
#   Copyright (C) 2010  Serge A. Timchenko
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program. If not, see <http://www.gnu.org/licenses/>.
#

# 


# Translate CGI module
# 'radiogrom.com' plug-in
#
# version: 1.0 
#
# http://www.radiogrom.com/online/great_britain/capital_fm_london_95_8_online.html
#

stream_type=''
stream_url=''
server_type=''

if echo "${arg_url}" | grep -q -s '\(www\.\)*radiogrom\.com/online/.*\.html$'; then 

  local host_response=`$MSDL -q -o ${TMPFILE} -p http --useragent "${USERAGENT}" "${arg_url}" 2>&1`
  
  if [ -f ${TMPFILE} ]; then
    arg_url=`grep 'var file = ' "$TMPFILE" | sed 's/.*= "//;s/".*//'`;
    local station_title=`grep "<title>" "$TMPFILE" | sed 's/.*<title>//;s/<\/title>.*//'`;
    rm -f "$TMPFILE"
    check_av_stream
    local prev=
    while [ "$prev" != "$stream_url" -a "$stream_class" == "playlist" ];
    do
      prev=$stream_url
      check_playlist
    done
    [ -z "$ms_title" ] && ms_title="$station_title"
    [ -z "$icy_name" ] && icy_name="$station_title"
    [ -z "$icy_description" ] && icy_description="$station_title"
    return $RC_OK
  fi
else
  check_av_stream
fi

return $RC_FAIL
